//懒加载组件
const Home = () => import("@/pages/Home");
const Login = () => import("@/pages/Login");
const Search = () => import("@/pages/Search");
const Register = () => import("@/pages/Register");
const Test = () => import("@/pages/Test");
const AddCartSuccess = () => import("@/pages/AddCartSuccess");
const ShopCart = () => import("@/pages/ShopCart")
const Trade = () =>import("@/pages/Trade")
const Pay = () => import("@/pages/Pay")
const Detail = () => import("@/pages/Detail")
const PaySuccess = () => import("@/pages/PaySuccess")
const Center = () => import("@/pages/Center")

export default[
    {
        path: "/",
        component: Home
    },
    {
        path: "/login",
        component: Login,
        meta:{
            isHiddenFooter:true  //是否隐藏footer
        }
    },
    {
        path: "/register",
        component: Register,
        meta:{
            isHiddenFooter:true  //是否隐藏footer
        }
    },
    {
        path: "/search",
        component: Search
    },
    {
        path: "/detail/:id",
        component:Detail
    },
    {
        path:"/addcart_success",
        component:AddCartSuccess,
        beforeEnter(to,from,next){  //局部路由守卫
            if(from.path.slice(0,7) === "/detail"){
                next();
            }else{
                next("/")
            }
        }
    },
    {
        path:"/shopcart",
        component:ShopCart
    },
    {
        path:"/trade",
        component:Trade,
        meta:{
            isLogin:true   // 是否验证登录
        }
    },
    {
        path:"/pay",
        component:Pay,
        beforeEnter(to,from,next){
            if(from.path === "/trade"){
                next();
            }else{
                next("/")
            }
        }
    },
    {
        path:"/paysuccess",
        component:PaySuccess
    },
    {
        path:"/center",
        component:Center
    },
    {
        path:"/test",
        component:Test
    },
    {
        path:"*",
        redirect:"/"
    }
] 